<?php
/**
 * Created by PhpStorm.
 * User: yafex
 * Date: 2019/12/14
 * Time: 10:10
 */
class ctrl_ali_task extends L {

    /**
     * 描述：获取阿里产品信息
     * 作者：Zoro.Zhu
    **/
    public static function updProductInfo(){
        set_time_limit(0);
        $sqlQ = "SELECT
            `productId`, `account`, `data`, `pddId`
        FROM
            `ali_product` 
        WHERE
            `state` = 50 
        AND 'account' = 'pdd57838014118'";
        while (of_base_com_com::eachSql($sqlQ, $aliProduct, 'default', 100)) {
            foreach($aliProduct as $row){
                $info = serv_rapi_ali::getAliProduct($row['productId']);
                //商品状态。published:上网状态;member expired:会员撤销;auto expired:自然过期;expired:过期(包含手动过期与自动过期);member deleted:会员删除;modified:修改;new:新发;deleted:删除;TBD:to be delete;approved:审批通过;auditing:审核中;untread:审核不通过;
                //阿里商品不是published状态的，就下架掉
                if(!empty($info['productInfo']['status']) && $info['productInfo']['status'] != 'published'){
                    $updStatusRes = serv_rapi_pdd::updProductStatus($row['pddId'], $row['account'], 0);
                    if(!empty($updStatusRes['goods_sale_status_set_response']['is_success'])){
                        $errorInfo = [
                            'info' => '阿里巴巴已下架',
                            'date' => date('Y-m-d H:i:s')
                        ];
                        $sql = "UPDATE `ali_product` 
                        SET 
                            `errorData` = '" . addslashes(json_encode($errorInfo)) . "',
                            `state` = 60 
                        WHERE
                            `productId` = '{$row['productId']}'";
                        L::sql($sql);
                    }
                }
            }
            unset($aliProduct);
        }

    }

}
return true;